package com.demo.gateway.filter;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

import java.util.Arrays;
import java.util.List;

/**
 *
 * @author
 * @since
 */
@Service
@Slf4j
public class GpDefineGatewayFilterFactory extends AbstractGatewayFilterFactory<GpDefineGatewayFilterFactory.GpConfig> {

  public GpDefineGatewayFilterFactory(){
    super(GpConfig.class);
  }


  @Override
  public GatewayFilter apply(GpConfig config) {
    return ((exchange, chain) -> {
      log.info("[Pre] filter request, name:{}", config.getFullName());
      return chain.filter(exchange).then(Mono.fromRunnable(() -> {
        log.info("[Post] response filter");
      }));
    });
  }

  /**
   *
   * @author
   * @since
   */
  public static class GpConfig {
    private String fullName;

    public void setFullName(String fullName){
      this.fullName = fullName;
    }

    public String getFullName(){
      return this.fullName;
    }
  }

}
